package 多线程.练习.callablePratice;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class CallablePratice {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Callable<Integer> task = new MyCallable();
        FutureTask<Integer> futureTask = new FutureTask<> (task);

        Thread thread = new Thread(futureTask);
        thread.start();

        System.out.println(futureTask.get());
    }
}

class MyCallable implements Callable<Integer> {
    @Override
    public Integer call() throws Exception {
        int sum = 0;
        for (int i = 1; i <= 1000; i++) {
            sum += i;
        }
        return sum;
    }
}
